const DynamicProgramming = require("../template")

function testFibonacciDetailed() {
  const dp = new DynamicProgramming()

  console.log(
    "1. 大数斐波那契测试:",
    (() => {
      return dp.fibonacci(20) === 6765 && dp.fibonacci(30) === 832040
    })()
  )

  console.log(
    "2. 斐波那契数列性能比较:",
    (() => {
      const n = 25
      const recursive = dp.fibonacci(n)
      const iterative = dp.fibonacciIterative(n)
      return recursive === iterative && recursive === 75025
    })()
  )

  console.log(
    "3. 边界情况测试:",
    (() => {
      return dp.fibonacci(0) === 0 && 
             dp.fibonacci(1) === 1 && 
             dp.fibonacci(2) === 1 &&
             dp.fibonacciIterative(0) === 0 && 
             dp.fibonacciIterative(1) === 1 && 
             dp.fibonacciIterative(2) === 1
    })()
  )

  console.log(
    "4. 负数情况测试:",
    (() => {
      try {
        dp.fibonacci(-1)
        return false // 应该抛出异常
      } catch (e) {
        return true // 正确抛出异常
      }
    })()
  )

  console.log(
    "5. 递归与迭代一致性测试:",
    (() => {
      const testCases = [0, 1, 2, 3, 4, 5, 10, 15]
      return testCases.every(n => dp.fibonacci(n) === dp.fibonacciIterative(n))
    })()
  )

  console.log(
    "6. 性能基准测试:",
    (() => {
      const start = performance.now()
      dp.fibonacci(30)
      const end = performance.now()
      return (end - start) < 1000 // 应该在1秒内完成
    })()
  )

  console.log(
    "7. 迭代版本性能测试:",
    (() => {
      const start = performance.now()
      dp.fibonacciIterative(30)
      const end = performance.now()
      return (end - start) < 100 // 迭代版本应该更快
    })()
  )

  console.log(
    "8. 大数计算准确性测试:",
    (() => {
      return dp.fibonacci(40) === 102334155 && dp.fibonacciIterative(40) === 102334155
    })()
  )
}

testFibonacciDetailed()
